function register_pseudoscans_toolbox(patient, scan)
% [folder] = uigetdir('Select Folder to Analyse');       % This overwrited dicom_dir saved for the data may be processed on another PC
folder_static= patient.folder_static;
% model_folder = 'E:\Patient_Data_E\pt2\pt2\model_params_5d_25scans\Psuedo_scans';
 scan_folder = [patient.model_folder '/Psuedo_scans' sprintf('/scan%d',scan)];

elastix_root=patient.elastix_root_folder;

    
  fixed = ['"' scan_folder sprintf('/pseudo_scan%d.mhd',  scan) '"']
  fixed_mask = ['"' scan_folder sprintf('/pseudo_mask%d.mhd',  scan) '"']
  
    moving=['"' folder_static sprintf('/scan_%d_cut.mhd', scan) '"']

out=[ scan_folder sprintf('/Registration')]

cmd=['mkdir "'  out '"' ]
system(cmd)

%  param1=['"' elastix_root '\Parameters', '\Parameters.MI.Coarse.Bspline_tuned_mask_GPU.txt' '"']
  param1=['"' 'E:\Elastix\Parameters', '\Parameters.MI.Fine.Bspline_tuned_mask.txt' '"']
% param3=['"' elastix_root  '\Parameters', '\Parameters.MI.RP.Bspline_tuned_mask.txt' '"']
% param1=['"' elastix_root '\Parameters', '\Parameters.Par0011.affine.txt' '"']
% param2=['"' elastix_root  '\Parameters', '\Parameters.Par0011.bspline1_s.txt' '"']
% param3=['"' elastix_root  '\Parameters', '\Parameters.Par0011.bspline2_s.txt' '"']


   elastix_cmd=['elastix -f ' fixed  ' -fMask ' fixed_mask ' -m ' moving ' -out "'  out  '" -p ' param1] 
%  elastix_cmd=['elastix -f ' fixed  ' -fMask ' fixed_mask ' -m ' moving ' -out ' '"' out '"' ' -p ' param1 ' -p ' param2  ' -p ' param3] 

 [status result]=system(elastix_cmd);

 transform_param=['"' out '\TransformParameters.0.txt' '"']
%  transform_param2=['"' out '\TransformParameters.2.txt' '"']

transformix_cmd=['transformix -def all -out ' '"' out '"' ' -tp ' transform_param] 
% [status result]=system(transformix_cmd, '-echo');
[status result]=system(transformix_cmd);


